package com.cy.ppj.web.admin.dealrecord;

import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cy.ppj.model.Result;
import com.cy.ppj.model.ao.dealrecord.SysRewardOrDeductAO;
import com.cy.ppj.model.dto.account.AccountAmountDTO;
import com.cy.ppj.model.enums.DealType;
import com.cy.ppj.service.account.AccountService;
import com.cy.ppj.web.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 后台-交易记录管理
 *
 * @author: tanyilin
 * @create: 2018年10月15日 上午10:32:20
 */
@Slf4j
@RestController
@RequestMapping("/admin/deal/record")
@Api(tags = "后台-交易记录管理")
public class AdminDealRecordController extends BaseController{

	@Autowired
	private AccountService accountService;
	
	@ApiOperation("系统奖励")
	@PostMapping("/sys/reward")
	public Result sysReward(@Validated SysRewardOrDeductAO sysRewardOrDeductAO, BindingResult bindingResult) {
		this.checkError(bindingResult);
		AccountAmountDTO accountAmountDTO = new AccountAmountDTO();
		BeanUtils.copyProperties(sysRewardOrDeductAO, accountAmountDTO);
		accountAmountDTO.setRelationId(0L);
		accountAmountDTO.setType(DealType.SYSTEM_REWARD);
		accountAmountDTO.setUpdateTime(new Date());
		accountService.transaction(accountAmountDTO);
		return ok();
	}
	
	@ApiOperation("系统扣除")
	@PostMapping("/sys/deduct")
	public Result sysDeduct(@Validated SysRewardOrDeductAO sysRewardOrDeductAO, BindingResult bindingResult) {
		this.checkError(bindingResult);
		AccountAmountDTO accountAmountDTO = new AccountAmountDTO();
		BeanUtils.copyProperties(sysRewardOrDeductAO, accountAmountDTO);
		accountAmountDTO.setRelationId(0L);
		accountAmountDTO.setType(DealType.SYSTEM_DEDUCT);
		accountAmountDTO.setUpdateTime(new Date());
		accountService.transaction(accountAmountDTO);
		return ok();
	}
	
}
